
__all__ = ('current_app', 'current_loop', 'hub', 'is_running', 'halt')

import os
import signal

from . import core


ALARM_DELAY_FAST =  5
ALARM_DELAY_SLOW = 10

current_app = None


def current_loop():
	return core.current_loop


def hub():
	return current_app.hub


def is_running():
	return current_app is not None


def halt(reason=None):
	signal.alarm(ALARM_DELAY_FAST if reason is not None else ALARM_DELAY_SLOW)
	try:
		if current_app is not None:
			current_app.halt(reason)
	except:
		os._exit(255)
